package CI.aufgabe2.cip.mynodes;

import CI.aufgabe2.cip.SymbolTable;
import CI.aufgabe2.cip.base.AbstractDescr;
import CI.aufgabe2.cip.descriptor.SimpleTypeDescr;

public class MyFPSectionNode extends MyAbstractNode {

	private static final long serialVersionUID = 1L;

	private final MyIdentListNode identList;
	private final MyAbstractNode type;
	private AbstractDescr sectiontype;
	private final boolean var;

	public MyFPSectionNode(MyIdentListNode identList, MyAbstractNode type,
			boolean var) {
		this.identList = identList;
		this.type = type;
		this.sectiontype = null;
		this.var = var;
	}

	@Override
	public void print() {
		trace("FPSectionNode ");

		if (identList != null)
			identList.print();

		if (type != null)
			type.print();

		unindent();
	}

	public AbstractDescr compile(SymbolTable sym) {
		AbstractDescr desc = null;
//		if (this.var) {
//			
//		} else {
			if (type instanceof MyIdNode) {
				String val = ((MyIdNode) type).strval;
				if (val.equals("integer")) {
					desc = new SimpleTypeDescr(val);
				} else if (val.equals("string")) {
					desc = new SimpleTypeDescr(val);
				} else {
					desc = sym.getDescr(val);
				}
			} else {
				desc = type.compile(sym);
			}

			MyIdentListNode node = (MyIdentListNode) this.identList;
			node.compileParams(sym, desc,this.var);
			sectiontype = desc;
//		}
		return null;
	}

	public int getSize() {
		MyIdentListNode node = (MyIdentListNode) identList;
		return node.getSize() * sectiontype.getSize();
	}
	
	public boolean getVarState(){
		return this.var;
	}
	public MyIdentListNode getIdentList(){
		return this.identList;
	}

}
